﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualDisk
{
    class MkdirCommand : Command
    {
        private MyString[] arguments = null;

        protected override void processError(int returnCode)
        {
            switch (returnCode)
            {
                case 1:
                    Console.WriteLine("命令语法不正确");
                    break;
                case 2:
                    Console.WriteLine("文件名、目录名或卷标语法不正确。");
                    break;
                default:
                    break;
            }
        }

        protected override int run()
        {

            if (arguments == null || arguments.Length == 0)
            {
                return 1;
            }
            foreach (MyString str in arguments)
            {
                MyString path = str.Trim();
                if (!DiskHelper.isLegalPath(path))
                {
                    return 2;
                }

                if (DiskTree.getInstance().isExist(path))
                {
                    Console.WriteLine("子目录" + path + "已经存在！");
                }
                else
                {
                    DiskTree.getInstance().createNode(path);
                }

            }
            return 0;

        }

        public MkdirCommand(MyString[] argu)
        {
            if (argu != null)
            {
                arguments = new MyString[argu.Length];
                for (int i = 0; i < arguments.Length; i++)
                {
                    arguments[i] = argu[i];
                }
            }
        }
    }
}
